package com.xyzq.reks.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.appfuse.model.BaseObject;

@Entity
@Table(name = "account_fund")
public class AccountFund extends BaseObject implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6633610759106868817L;
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "FK_ACCOUNT_ACCOUNT", nullable = false)
	private Account account;
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "FK_COMPANYFUND_CODE", nullable = false)
	private CompanyFund fund;
	@Column(scale = 2)
	private Double worth;
	@Temporal(TemporalType.DATE)
	@Column(name = "day")
	private Date day;
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "sub_time")
	private Date subTime;

	public Long getId() {
		return id;
	}

	public Account getAccount() {
		return account;
	}

	public CompanyFund getFund() {
		return fund;
	}

	public Double getWorth() {
		return worth;
	}

	public Date getDay() {
		return day;
	}

	public Date getSubTime() {
		return subTime;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setAccount(Account account) {
		this.account = account;
	}

	public void setFund(CompanyFund fund) {
		this.fund = fund;
	}

	public void setWorth(Double worth) {
		this.worth = worth;
	}

	public void setDay(Date day) {
		this.day = day;
	}

	public void setSubTime(Date subTime) {
		this.subTime = subTime;
	}

	@Override
	public String toString() {
		ToStringBuilder builder = new ToStringBuilder(this,
				ToStringStyle.DEFAULT_STYLE);
		builder.append("id", id);
		builder.append("account", account);
		builder.append("fund", fund);
		builder.append("worth", worth);
		builder.append("day", day);
		builder.append("subTime", subTime);
		return builder.toString();
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		AccountFund other = (AccountFund) obj;
		if (account == null) {
			if (other.account != null)
				return false;
		} else if (!account.equals(other.account))
			return false;
		if (day == null) {
			if (other.day != null)
				return false;
		} else if (!day.equals(other.day))
			return false;
		if (fund == null) {
			if (other.fund != null)
				return false;
		} else if (!fund.equals(other.fund))
			return false;
		if (subTime == null) {
			if (other.subTime != null)
				return false;
		} else if (!subTime.equals(other.subTime))
			return false;
		if (worth == null) {
			if (other.worth != null)
				return false;
		} else if (!worth.equals(other.worth))
			return false;
		return true;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((account == null) ? 0 : account.hashCode());
		result = prime * result + ((day == null) ? 0 : day.hashCode());
		result = prime * result + ((fund == null) ? 0 : fund.hashCode());
		result = prime * result + ((subTime == null) ? 0 : subTime.hashCode());
		result = prime * result + ((worth == null) ? 0 : worth.hashCode());
		return result;
	}

}
